<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
        forEach
        map
        filter
        reduce
        */

        // let arr = [1, 2, 3]
        let add = 0
        //es6遍历

        /*   let arr = [1, 2, 3]
          let add = 0;
          arr.forEach((val, index) => {
              console.log(index)
              console.log(val);
              add += val;
          })
          console.log(add) */

        /*  arr.forEach((item, index) => {
             add += item;
             if (index === arr.length - 1) {
                 console.log(add)
             }
         }) */

        //filter 必须要有返回值 而且返回值是一个布尔变量  true false 执行完后返回一个新数组
        let arr = [40, 50, 60]
        let newArr = arr.filter((val, index) => {
            console.log(val)
            if (val >= 50) {
                return true
            }
        })
        console.log(newArr);
    </script>
</body>

</html>